package day3;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class SetTest {
    public static void main(String[] args) {
        //集合,hashSet，TreeSet
        Set s=new HashSet();
        s.add("老虎");
        s.add("狮子");
        s.add("狼");
        s.add("狮子");
        System.out.println(s.size());
        System.out.println(s);
        //遍历 1：增强For,最简单
        for(Object o:s)
            System.out.print(o+" ");
        System.out.println();
        //2:转换成数组
        Object[] ar = s.toArray();
        //3:迭代器。。。
        System.out.println(">>>>>>>>>>迭代器>>>>>>>>>>>>>>>>>>>");
        Iterator ir = s.iterator();
        while (ir.hasNext()){
            Object value = ir.next();
            System.out.println(value);
        }
        Set s2=new HashSet();
        s2.add("老虎");
        s2.add("狮子");
        s2.add("公鸡");
        s2.retainAll(s);
        System.out.println("交集:"+s2);
    }
}
